public class MyQueue {
    public Node head;
    public Node tail;

    public void offer(int val){
        Node node = new Node(val);
        if (head == null){
            head = node;
            tail = node;
        }else{
            tail.next = node;
            tail = tail.next;
        }
    }

    public int poll(){
        int result;
        if (head == null){
            throw new RuntimeException("队列为空！");
        }else{
            result = head.val;
            head = head.next;
        }
        return result;
    }

    public int peek(){
        if (head == null){
            throw new RuntimeException("队列为空！");
        }
        return head.val;
    }
}

class Node{
    public int val;
    public Node next;

    public Node(int val) {
        this.val = val;
    }
}